package com.hck.trigger.http;

import com.hck.api.model.DoctorLoginRequestDTO;
import com.hck.api.model.DoctorLoginResponseDTO;
import com.hck.api.model.UserLoginResponseDTO;
import com.hck.domain.doctor.model.entity.DoctorEntity;
import com.hck.domain.doctor.service.IDoctorService;
import com.hck.types.model.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * DoctorController class description here.
 *
 * @author 黄朝看
 * @date 2025/7/2
 */
@RestController
@RequestMapping("/api/doctor")
@Tag(name = "医生接口", description = "医生相关操作")
public class DoctorController {

    @Resource
    private IDoctorService doctorService;

    @PostMapping("/login")
    @Operation(summary = "医生登录", description = "通过账号和密码登录")
    public Response<DoctorLoginResponseDTO> login(@RequestBody DoctorLoginRequestDTO requestDTO){
       DoctorLoginResponseDTO responseDTO = doctorService.login(requestDTO);

        if (responseDTO.getSuccess()) {
            return Response.<DoctorLoginResponseDTO>builder()
                    .code("200")
                    .data(responseDTO)
                    .info("登录成功")
                    .build();
        }

        return Response.<DoctorLoginResponseDTO>builder()
                .code("400")
                .data(responseDTO)
                .info(responseDTO.getErrorMessage())
                .build();
    }

    @GetMapping("/info/{doctorId}")
    @Operation(summary = "获取医生信息", description = "根据医生ID获取医生详细信息")
    public Response<DoctorEntity> getDoctorInfo(@PathVariable Long doctorId) {
        DoctorEntity doctorInfo = doctorService.getDoctorInfo(doctorId);

        if (doctorInfo != null) {
            return Response.<DoctorEntity>builder()
                    .code("200")
                    .data(doctorInfo)
                    .info("获取成功")
                    .build();
        } else {
            return Response.<DoctorEntity>builder()
                    .code("404")
                    .data(null)
                    .info("医生不存在")
                    .build();
        }
    }

    @GetMapping("/list")
    @Operation(summary = "获取医生列表", description = "获取所有医生的基本信息")
    public Response<List<DoctorEntity>> getDoctorList() {
        List<DoctorEntity> doctorList = doctorService.getAllDoctors();
        return Response.<List<DoctorEntity>>builder()
                .code("200")
                .data(doctorList)
                .info("获取成功")
                .build();
    }
}  
